package com.diaohw.platform.common.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Data
@Component
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "platform.log")
public class LogProperties {
    /**
     * http 日志
     */
    private boolean http;
    /**
     * SQL日志
     */
    private boolean db;

    private boolean get;

    private boolean post;

    private boolean update;

    private boolean delete;

    public boolean enable() {
        return http || db;
    }

    public boolean http(String method) {
        if (!http) {
            return false;
        }

        return switch (method) {
            case "GET" -> get;
            case "POST" -> post;
            case "PUT" -> update;
            case "DELETE" -> delete;
            default -> false;
        };
    }

}
